

function addSensorbitCod(Blockly) {



//声音传感器模块
Blockly.Python.microbit_vioce = function(block) {
    var dropdown_vioceDigital = this.getFieldValue('vioceDigital');
    var dropdown_vioceAnalog = this.getFieldValue('vioceAnalog');
    // var dropdown_vioceValue = this.getFieldValue('vioceValue');
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
    Blockly.Python.definitions_['import_Sound'] = 'from sensor import sound';
    Blockly.Python.definitions_['import_vioceDigital' ] = 'vioceDigitalPort = '+dropdown_vioceDigital;
    Blockly.Python.definitions_['import_vioceAnalog' ] = 'vioceAnalogPort = '+dropdown_vioceAnalog;
    return '';
  }

  // // 获取声音的数字值
  Blockly.Python.microbit_vioceDigital = function(block) {
    Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
    Blockly.Python.definitions_['import_Sound'] = 'from sensor import sound';
    var dropdown_vioceDigital = this.getFieldValue('vioceDigital');
    Blockly.Python.definitions_['import_vioceDigital' + dropdown_vioceDigital] = 'vioceDigitalPort' + dropdown_vioceDigital + ' = ' + dropdown_vioceDigital;
    var code = "sound.is_detected(vioceDigitalPort" + dropdown_vioceDigital + ")";
    return [code];
  }
//  获取声音的模拟值
Blockly.Python.microbit_vioceAnalog = function(block) {
  Blockly.Python.definitions_['import_microbit'] = 'from microbit import *';
    Blockly.Python.definitions_['import_Sound'] = 'from sensor import sound';
    var dropdown_vioceAnalog = this.getFieldValue('vioceAnalog');
    Blockly.Python.definitions_['import_vioceAnalog' + dropdown_vioceAnalog] = 'vioceAnalogPort' + dropdown_vioceAnalog + ' = ' + dropdown_vioceAnalog;
  var code = "sound.get_value(vioceAnalogPort" + dropdown_vioceAnalog + ")";
    return [code];
}

    return Blockly;
}

module.exports = addSensorbitCod;

